package com.vmove.childtrain.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.vmove.childtrain.R;
import com.vmove.childtrain.utils.LogUtils;

import java.text.DecimalFormat;

import androidx.annotation.Nullable;
import androidx.fragment.app.BaseDialogFragment;
import androidx.fragment.app.DialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 单组成绩显示框
 */
public class DegreeDialog_lesson1 extends BaseDialogFragment {


    TextView tvTitle;
    ImageView ivClose;
    TextView tvTimeCost;
    TextView tvSuccess;
    TextView tvFailed;
    private View rootView;

    Unbinder unbinder;

    private int timeCost;
    private int success;
    private int faild;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.dialog_degree_lesson1, container, false);
//        unbinder = ButterKnife.bind(this, rootView);
        initView(rootView);
        return rootView;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog_NoActionBar_MinWidth);
        Bundle args = getArguments();
        timeCost = args.getInt("time", 0);
        success = args.getInt("success",0);
        faild = args.getInt("faild",0);
    }

    private void setData(int time1, int success, int failed){
        tvFailed.setText(failed+"次");
        tvSuccess.setText(success+"分");
        float time = timeCost/1000f;
        DecimalFormat df = new DecimalFormat("0.00");
        String format = df.format(time);
        String[] split = format.split("\\.");
        tvTimeCost.setText(split[0]+"秒"+split[1]);
    }


    /**
     * 定义控件
     *
     * @param rootView
     */
    private void initView(View rootView) {
        tvFailed = rootView.findViewById(R.id.tv_failed);
        tvTimeCost = rootView.findViewById(R.id.tv_timeCost);
        tvSuccess = rootView.findViewById(R.id.tv_success);
        ivClose = rootView.findViewById(R.id.iv_close);
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DegreeDialog_lesson1.this.dismiss();
            }
        });
        setData(timeCost, success, faild);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (null != unbinder) {
//            unbinder.unbind();
        }
    }

}
